package GUI.Season;

import java.util.Vector;

import data.Episode;
import data.Season;
import GUI.SonnyTableModel;

public class SeasonTableModel extends SonnyTableModel 
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Vector<String> selectedEpisode = new Vector<String>();
	private Vector<String> episodesDownloaded = new Vector<String>();
	

	public SeasonTableModel(String[] columnNames, Season season) 
	{
		super(columnNames, (Object[][]) null);
		this.setData(parseEpisodeData(season));
		this.fireTableDataChanged();
	}
	public Vector<String> getSelectedEpisode()
	{
		return selectedEpisode;
	}

	public Object[][] parseEpisodeData(Season s)
	{
		Vector<Episode> episodes = s.getEpisodes();
		String[][] returnString = new String[episodes.size()][5];
		for(int i=0; i<episodes.size(); i++)
		{
			Episode e = episodes.get(i);

			returnString[i][0] = "Episode " + e.getEpisodeNumber();
			returnString[i][1] = e.getEpisodeTitle();
			returnString[i][2] = e.getTorrentURL();
			returnString[i][3] = e.getDescription();
			returnString[i][4] = e.getAirDate().toString();
			
			if(s.getSelectedEpisode() == e)
			{
				for(String string : returnString[i])
				{
					selectedEpisode.add(string);
				}
			}
			else if(e.hasDownloaded())
			{
				for(String string : returnString[i])
				{
					episodesDownloaded.add(string);
				}
				
			}
		}
		return returnString;
		
	}

	public void rebuild(Season s) 
	{
		this.setData(this.parseEpisodeData(s));
		this.fireTableDataChanged();
	}
	public Vector<String> getDownloadedEpisodes() 
	{
		return episodesDownloaded;
	}

}
